<?php

class ManageModule extends CWebModule
{
	public function init()
	{
		
		// import the module-level models and components
		$this->setImport(array(
			'manage.models.*',
			'manage.components.*',
			'manage.controllers.BaseController',
		));
		//设置视图文件的位置
		$this->setViewPath(Yii::app()->basePath.'/views/manage');
		
		Yii::app()->setComponents(array(
				'user'=>array(
					'class'=>'CWebUser',
					'stateKeyPrefix'=>'admin',
					'loginUrl'=>'/manage/adminer/login',
					'returnUrl' => '/manage'
				)
		));
		
		
		
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			//定义控制器活动方法名，用于定位三级菜单焦点
			Yii::app()->getController()->active_action = $action->id;
			// 判断是否有管理员权限
			if($controller->id =='adminer' && ($action->id =='login'||$action->id =='captcha')){
				return true;
			}else{
				if(!Yii::app()->user->getstate('manage')==='admin'||Yii::app()->user->isGuest){
					Yii::app()->user->loginRequired();
				}
			}
		}
		return true;
	}
}
